﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Agile_E
{
    public partial class AddEmployees : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.IsInRole("Manager"))
            {
                Response.Redirect("~/Denied.aspx");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Employees newEmp = new Employees();
            try
            {
                newEmp.Info.LastName = txtlname.Text;
                newEmp.Info.MiddleName = txtmname.Text;
                newEmp.Info.FirstName = txtfname.Text;
                newEmp.IDNumber = txtEmpID.Text;
                newEmp.Position = txtPos.Text;
                newEmp.Supervisor = txtSuper.Text;
                newEmp.Info.Workphone = txtWphone.Text;
                newEmp.Info.Cell = txtcphone.Text;
                newEmp.Info.Homephone = txthphone.Text;
                newEmp.Specialty = txtSp.Text;
                if (ddldealerships.SelectedIndex > 0)
                {
                    newEmp.Dealership = ddldealerships.SelectedValue;
                    newEmp.Dealership_ID = ddldealerships.SelectedIndex+1;
                }
                else
                {
                    newEmp.Dealership = string.Empty;
                    newEmp.Dealership_ID = -1;
                }
                DatabaseHandler.connect();
                DatabaseHandler.addEmployee(newEmp);
                string firstname, middlename, lastname;
                firstname = newEmp.Info.FirstName;
                middlename = newEmp.Info.MiddleName;
                lastname = newEmp.Info.LastName;
                string status = firstname + " " + middlename + " " + lastname + " has been added";
                ((Main)this.Master).writeStatus(status, false);
            }
            catch (Exception ex)
            {
                ((Main)this.Master).writeStatus(ex.Message, true);
            }
        }
    }
}
